package cn.org.donald.base;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.Serializable;

/**
 * @author : Donald
 * @since : 2021/3/17 13:41
 */
public class BaseController implements Serializable {

    protected static final Logger logger = LoggerFactory.getLogger(BaseController.class);

    protected  HttpResult toSuccess(String info) {
        return this.toSuccess(info,null);
    }

    protected <T> HttpResult<T> toSuccess(T data) {
        return this.toSuccess("请求成功!", data);
    }

    protected <T> HttpResult<T> toSuccess(String info, T data) {

        return this.baseResult(200,info,data);
    }

    protected HttpResult toFail(String info) {
        return this.toFail(500, info);
    }

    protected HttpResult toFail(Integer code, String info) {
        return this.baseResult(code, info, null);
    }


    private <T> HttpResult<T> baseResult(Integer code, String info, T data) {
        HttpResult<T> result = new HttpResult<>();
        result.setInfo(info);
        result.setCode(code);
        result.setData(data);
        return result;
    }
}
